Problem Set - Binary Unsigned Division
Tags: #◇Computer Science #◇CSARCH2 #◇Computer Architecture #◇Binary Arithmetic #◇Division #◇Restoring Division #◇Non-Restoring Division #◇ALU
◇Overview
Binary integer division is the most computationally demanding basic arithmetic operation executed by the Arithmetic Logic Unit (◇ALU). Unlike multiplication—which can be implemented as parallel summations or bit-pair recoding—division cannot easily compute reciprocals in fixed-point integer hardware. Consequently, hardware integer division is fundamentally performed via sequential digit-recurrence algorithms based on shift-and-subtract operations.
┌──────────────────────────────────────────────────────────┐
│ Binary Integer Division │
└────────────────────────────┬─────────────────────────────┘
│
┌──────────────────────────────┴──────────────────────────────┐
▼ ▼
┌─────────────────────────┐ ┌─────────────────────────┐
│ Restoring Division │ │ Non-Restoring Division │
│ (Trial Subtraction with │ │ (Deferred Correction to │
│ Immediate Restore) │ │ Next Cycle) │
└────────────┬────────────┘ └────────────┬────────────┘
│ │
┌────────────┴────────────┐ ┌────────────┴────────────┐
▼ ▼ ▼ ▼
┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐
│ If A < 0: │ │ If A >= 0: │ │ If Prev A < 0: │ │ If Prev A >= 0: │
│ - Restore: A <- A+M │ │ - Keep A │ │ - Shift Left AQ │ │ - Shift Left AQ │
│ - Set Q_0 <- 0 │ │ - Set Q_0 <- 1 │ │ - Add M: A <- A+M │ │ - Sub M: A <- A-M │
└─────────────────────┘ └─────────────────────┘ │ - Set Q_0 <- ~A_MSB │ │ - Set Q_0 <- ~A_MSB │
└─────────────────────┘ └─────────────────────┘
Every integer division operation satisfies the fundamental Division Invariant:
where:
- is the Dividend (stored initially in Register )
- is the Divisor (stored in Register )
- is the generated Quotient (accumulated in Register )
- is the final Remainder (accumulated in Register )
This problem set examines two foundational hardware division algorithms:
- Restoring Division: Performs a trial subtraction; if the partial remainder becomes negative, it immediately restores the previous value by adding the divisor back.
- Non-Restoring Division: Eliminates the intermediate restoring addition by deferring compensation to the next cycle (adding rather than subtracting), significantly optimizing hardware execution time.
◇Theoretical Principles & Hardware Datapath
1. Register Architecture & Sizing Conventions
For an unsigned dividend of bits and a divisor of bits:
- Quotient/Dividend Register (): Holds the -bit dividend initially. As bits shift left during each pass, newly determined quotient bits () are inserted at the LSB. Length = bits.
- Divisor Register (): Holds the divisor with 1 extra bit appended at the MSB to function as a sign bit. Length = bits.
- Two's Complement Divisor (): Computed as using bits.
- Accumulator Register (): Holds partial remainders. Initialized to all zeros (). Length = bits (where is the sign bit).
- Pass Counter: Initialized to (the number of bits in dividend ).
┌───────────────────────────────────┐
│ Divisor Register (M) │ (k+1 bits)
└─────────────────┬─────────────────┘
│
▼
┌─────────────────────────────┬─────────────────────────────┐
│ Accumulator (A) │ Dividend / Quotient (Q) │
│ (k+1 bits) │ (k bits) │
└─────────────────────────────┴─────────────────────────────┘
▲ ▲
│ │
└─── [ Left Shift Registers ] ──┘
(AQ << 1)
2. Restoring Division Algorithm
In restoring division, the quotient bit is determined by trial subtraction. If the subtraction produces a negative remainder (), the trial subtraction is declared invalid, the accumulator is restored by adding back, and is set to .
Algorithmic Execution Steps:
- Initialization:
- ( bits)
- ( bits)
- ( bits)
- ( bits)
- Loop for Passes (one pass per bit of dividend ):
- Step 1 (Shift Left): Shift the combined register left by 1 bit:
(The MSB of shifts into the LSB of , and the LSB of becomes vacant). - Step 2 (Trial Subtraction): Subtract the divisor:
- Step 3 (Sign Evaluation & Restoration):
- Step 1 (Shift Left): Shift the combined register left by 1 bit:
- If is negative ():
- Restore:
- Set Quotient Bit:
- If is non-negative ():
- Keep Subtracted Value (No restoration)
- Set Quotient Bit:
- Termination: After passes:
- The quotient resides in .
- The remainder resides in .
3. Non-Restoring Division Algorithm
Non-Restoring Division eliminates the conditional restoring addition within the loop by exploiting the following algebraic identity:
Instead of restoring by and then shifting and subtracting (), the hardware simply shifts the un-restored negative value () and adds in the subsequent cycle.
Algorithmic Execution Steps:
- Initialization:
- ( bits)
- ( bits)
- ( bits)
- ( bits)
- Loop for Passes:
- Check the sign bit () of the previous accumulator value:
- Case A: Previous is Negative ():
- Shift left by 1 bit:
- Add Divisor:
- Case B: Previous is Non-Negative ():
- Shift left by 1 bit:
- Subtract Divisor:
- Quotient Bit Assignment:
- Set to the logical complement of the new sign bit of :
- Final Correction (Post-Loop Restoration):
- After completing all passes, check the final sign bit of :
- If (negative remainder), perform a final restoration:
- If (non-negative remainder), no restoration is required.
- Result: Quotient in , Remainder in .
◇Step-by-Step Problem Solutions:
Problem Setup & Register Bit Sizing
We evaluate the division of by :
Register Bit Widths:
- Dividend (): Fewest unsigned bits ( bits).
- Divisor (): Represented using bits (5 magnitude bits + 1 sign bit):
- Two's Complement of Divisor ():
- Accumulator (): Initialized to bits of zeros:
- Dividend / Quotient Register (): Initialized to bits:
- Total Passes: passes.
Try #1: using Restoring Division
Comprehensive Cycle-by-Cycle Execution Trace:
========================================================================================
INITIAL STATE:
M = 000111 -M = 111001
A = 000000 Q = 11011
========================================================================================
PASS 1:
1. Shift Left AQ:
A = 000001 Q = 1011_ (MSB of Q shifted into A)
2. Subtract M (A <-- A + (-M)):
A: 000001
+ (-M): 111001
--------------
A: 111010
3. Sign Check: A_5 = 1 (Negative)
--> Restore A (A <-- A + M):
A: 111010
+ M: 000111
-------------
A: 000001
--> Set Q_0 <-- 0: Q becomes 10110
>>> End of 1st Pass: A = 000001, Q = 10110
PASS 2:
1. Shift Left AQ:
A = 000011 Q = 0110_ (MSB of Q shifted into A)
2. Subtract M (A <-- A + (-M)):
A: 000011
+ (-M): 111001
--------------
A: 111100
3. Sign Check: A_5 = 1 (Negative)
--> Restore A (A <-- A + M):
A: 111100
+ M: 000111
-------------
A: 000011
--> Set Q_0 <-- 0: Q becomes 01100
>>> End of 2nd Pass: A = 000011, Q = 01100
PASS 3:
1. Shift Left AQ:
A = 000110 Q = 1100_ (MSB of Q shifted into A)
2. Subtract M (A <-- A + (-M)):
A: 000110
+ (-M): 111001
--------------
A: 111111
3. Sign Check: A_5 = 1 (Negative)
--> Restore A (A <-- A + M):
A: 111111
+ M: 000111
-------------
A: 000110
--> Set Q_0 <-- 0: Q becomes 11000
>>> End of 3rd Pass: A = 000110, Q = 11000
PASS 4:
1. Shift Left AQ:
A = 001101 Q = 1000_ (MSB of Q shifted into A; A = 13 in decimal)
2. Subtract M (A <-- A + (-M)):
A: 001101
+ (-M): 111001
--------------
A: 1000110 --> Truncated 6-bit A = 000110 (+6 in decimal)
3. Sign Check: A_5 = 0 (Non-negative)
--> No Restoration Needed (Keep A = 000110)
--> Set Q_0 <-- 1: Q becomes 10001
>>> End of 4th Pass: A = 000110, Q = 10001
PASS 5:
1. Shift Left AQ:
A = 001101 Q = 0001_ (MSB of Q shifted into A; A = 13 in decimal)
2. Subtract M (A <-- A + (-M)):
A: 001101
+ (-M): 111001
--------------
A: 1000110 --> Truncated 6-bit A = 000110 (+6 in decimal)
3. Sign Check: A_5 = 0 (Non-negative)
--> No Restoration Needed (Keep A = 000110)
--> Set Q_0 <-- 1: Q becomes 00011
>>> End of 5th Pass: A = 000110, Q = 00011
========================================================================================
Official Solution Table (Try #1 - Restoring Division)
| After this pass | Register A | Register Q | Detailed Operation & Restoration Status |
|---|---|---|---|
| Initial | 000000 | 11011 | Initialize , , |
000001 | 10110 | Shift left ; (neg) Restore ; | |
000011 | 01100 | Shift left ; (neg) Restore ; | |
000110 | 11000 | Shift left ; (neg) Restore ; | |
000110 | 10001 | Shift left ; (pos) No restore; | |
000110 | 00011 | Shift left ; (pos) No restore; |
Result Verification:
- Quotient ():
- Remainder ():
- Mathematical Check:
Try #2: using Non-Restoring Division
Comprehensive Cycle-by-Cycle Execution Trace:
========================================================================================
INITIAL STATE:
M = 000111 -M = 111001
A = 000000 Q = 11011
========================================================================================
PASS 1:
Previous A = 000000 (A_5 = 0, Non-negative)
1. Shift Left AQ:
A = 000001 Q = 1011_
2. Subtract M (A <-- A + (-M)):
A: 000001
+ (-M): 111001
--------------
A: 111010
3. Sign Check & Quotient Bit:
New A_5 = 1 (Negative) --> Set Q_0 <-- NOT(1) = 0: Q becomes 10110
>>> End of 1st Pass: A = 111010, Q = 10110
PASS 2:
Previous A = 111010 (A_5 = 1, Negative)
1. Shift Left AQ:
A was 111010 --> Shift left with MSB of Q (1) --> A = 110101
Q = 0110_
2. Add M (A <-- A + M):
A: 110101 (-11 in decimal)
+ M: 000111 (+7 in decimal)
--------------
A: 111100 (-4 in decimal)
3. Sign Check & Quotient Bit:
New A_5 = 1 (Negative) --> Set Q_0 <-- NOT(1) = 0: Q becomes 01100
>>> End of 2nd Pass: A = 111100, Q = 01100
PASS 3:
Previous A = 111100 (A_5 = 1, Negative)
1. Shift Left AQ:
A was 111100 --> Shift left with MSB of Q (0) --> A = 111000
Q = 1100_
2. Add M (A <-- A + M):
A: 111000 (-8 in decimal)
+ M: 000111 (+7 in decimal)
--------------
A: 111111 (-1 in decimal)
3. Sign Check & Quotient Bit:
New A_5 = 1 (Negative) --> Set Q_0 <-- NOT(1) = 0: Q becomes 11000
>>> End of 3rd Pass: A = 111111, Q = 11000
PASS 4:
Previous A = 111111 (A_5 = 1, Negative)
1. Shift Left AQ:
A was 111111 --> Shift left with MSB of Q (1) --> A = 111111
Q = 1000_
2. Add M (A <-- A + M):
A: 111111 (-1 in decimal)
+ M: 000111 (+7 in decimal)
--------------
A: 1000110 --> Truncated 6-bit A = 000110 (+6 in decimal)
3. Sign Check & Quotient Bit:
New A_5 = 0 (Non-negative) --> Set Q_0 <-- NOT(0) = 1: Q becomes 10001
>>> End of 4th Pass: A = 000110, Q = 10001
PASS 5:
Previous A = 000110 (A_5 = 0, Non-negative)
1. Shift Left AQ:
A was 000110 --> Shift left with MSB of Q (1) --> A = 001101 (+13 in decimal)
Q = 0001_
2. Subtract M (A <-- A + (-M)):
A: 001101 (+13 in decimal)
+ (-M): 111001 (-7 in decimal)
--------------
A: 1000110 --> Truncated 6-bit A = 000110 (+6 in decimal)
3. Sign Check & Quotient Bit:
New A_5 = 0 (Non-negative) --> Set Q_0 <-- NOT(0) = 1: Q becomes 00011
>>> End of 5th Pass: A = 000110, Q = 00011
FINAL CORRECTION STEP:
Check sign of final A: A_5 = 0 (Non-negative).
--> No post-loop restoration required! (A remains 000110)
========================================================================================
Official Solution Table (Try #2 - Non-Restoring Division)
| After this pass | Register A | Register Q | Detailed ALU Operation & Direction |
|---|---|---|---|
| Initial | 000000 | 11011 | Initialize , , |
111010 | 10110 | Prev Shift left ; ; | |
111100 | 01100 | Prev Shift left ; ; | |
111111 | 11000 | Prev Shift left ; ; | |
000110 | 10001 | Prev Shift left ; ; | |
000110 | 00011 | Prev Shift left ; ; | |
| Final Check | 000110 | 00011 | No final restoration needed |
Result Verification:
- Quotient ():
- Remainder ():
- Mathematical Invariant Check:
◇Comparison of Restoring vs. Non-Restoring Division
| Metric / Feature | Restoring Division | Non-Restoring Division |
|---|---|---|
| ALU Operations per Cycle | 1 subtraction + 1 conditional addition (restore) | Exactly 1 addition OR 1 subtraction |
| Maximum Operations | Up to arithmetic additions/subtractions | At most operations (including final restore) |
| Execution Delay | Variable and slower (due to conditional restoring step) | Uniform, constant, and significantly faster |
| Intermediate Accumulator Value | Always represents the true, non-negative remainder | Represents an un-restored signed shifted residue |
| Quotient Bit Assignment | if , if restored | |
| Hardware Control Complexity | Requires multiplexer / register rollback logic | Requires simple 1-bit state memory of previous sign |
| Final Correction Requirement | Never needed (restored immediately in each pass) | Required if and only if final () |
◇Key Takeaways
- Sign Bit Allocation: Accumulator register and divisor register must always be allocated with 1 extra bit beyond the dividend width to function as an explicit sign bit () during intermediate subtractions.
- Restoration Elimination: Non-restoring division completely avoids intermediate restoration clock penalties by utilizing the property .
- Quotient Bit Derivation: In non-restoring division, the quotient bit is directly obtained by inverting the resulting sign bit ().
- Final Remainder Correctness: If the non-restoring division terminates with a negative remainder (), a single corrective addition () restores the true positive remainder without modifying the quotient register .
◇References & Navigation
- Related Notes: ◇Binary Division (Restoring & Non-Restoring)